JBoss Community Archive (Read Only)

Teiid 8.1

Temp Tables

Teiid supports creating temporary,or "temp", tables. Temp tables are dynamically created, but are treated as any other physical table.

Temp tables can be defined implicitly by referencing them in a INSERT statement or explicitly with a CREATE TABLE statement. Implicitly created temp tables must have a name that starts with '#'.

Creation syntax:

Explicit:

CREATE LOCAL TEMPORARY TABLE x \(column type \[NOT NULL], ... \[PRIMARY KEY \(column, ...)])

Implicit:

INSERT INTO #x \(column, ...) VALUES \(value, ...) 

If #x doesn't exist, it will be defined using the given column names and types from the value expressions.

Implicit:

INSERT INTO #x \[(column, ...)] select c1, c2 from t

If #x doesn't exist, it will be defined using the target column names (in not supplied, the column names will match the derived column names from the query), and the types from the query derived columns.

Drop syntax:

Primary Key Support

The following example is a series of statements that loads a temporary table with data from 2 sources, and with a manually inserted record, and then uses that temp table in a subsequent query.

... 
CREATE LOCAL TEMPORARY TABLE TEMP (a integer, b integer, c integer); 
SELECT * INTO temp FROM Src1; SELECT * INTO temp FROM Src2; 
INSERT INTO temp VALUES (1,2,3); 
SELECT a,b,c FROM Src3, temp WHERE Src3.a = temp.b; 
...

See Virtual Procedures for more on temp table usage.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-13 12:08:13 UTC, last content change 2012-08-14 17:29:43 UTC.